package com.ruibang.glass.sale.controller;


import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruibang.glass.sale.domain.req.GSaleDisputeReq;
import com.ruibang.glass.sale.entity.GSaleDispute;
import com.ruibang.glass.sale.mapper.GSaleDisputeProductMapper;
import com.ruibang.glass.sale.service.GSaleDisputeService;
import com.ruibang.glass.sale.service.GSaleReturnExchangeOrderService;
import com.teaming.cloud.framework2.common.model.ResultBody;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * @author mameng
 */
@Api(tags = "销售异议单")
@RestController
@RequestMapping("/api/glass/sale/dispute")
public class GSaleDisputeController {
    @Autowired
    private GSaleReturnExchangeOrderService gSaleReturnExchangeOrderService;

    @Autowired
    private GSaleDisputeService gSaleDisputeService;

    @Autowired
    private GSaleDisputeProductMapper gSaleDisputeProductMapper;

    @PostMapping("list")
    @ApiOperation(value = "销售异议单列表", response = ResultBody.class)
    public ResultBody list(@RequestBody GSaleDisputeReq disputeReq) {
        return ResultBody.success(gSaleDisputeService.getPage(disputeReq));
    }

    @PostMapping("addGSaleDispute")
    @ApiOperation(value = "增加异议单", response = ResultBody.class)
    public ResultBody addOrUpdate(@RequestBody GSaleDispute gSaleDisputeProduct) {
        gSaleDisputeService.addGSaleDispute(gSaleDisputeProduct);
        return ResultBody.success();
    }

    @PostMapping("updateGSaleDispute")
    @ApiOperation(value = "修改异议单", response = ResultBody.class)
    public ResultBody updateGSaleDispute(@RequestBody GSaleDispute gSaleDisputeProduct) {
        gSaleDisputeService.updateGSaleDispute(gSaleDisputeProduct);
        return ResultBody.success();
    }

    @GetMapping("removeById/{id}")
    @ApiOperation(value = "删除异议单", response = ResultBody.class)
    public ResultBody removeById(@PathVariable("id") String id) {
        gSaleDisputeProductMapper.deleteById(id);
        return ResultBody.success();
    }


    @GetMapping("getOne/{id}")
    @ApiOperation(value = "详情", response = ResultBody.class)
    public ResultBody addOrUpdate(@PathVariable("id") String id) {
        return ResultBody.success(gSaleDisputeService.getOneById(id));
    }

    @GetMapping("getDisputeList")
    @ApiOperation(value = "异议单下拉列表", response = ResultBody.class)
    public ResultBody getDisputeList() {
        return ResultBody.success(gSaleDisputeService.list(Wrappers.<GSaleDispute>lambdaQuery().select(GSaleDispute::getId,GSaleDispute::getDisputeNumber)));
    }


    @GetMapping("getDisputeNumber")
    @ApiOperation(value = "异议单号", response = ResultBody.class)
    public ResultBody getINNumber() {
        return ResultBody.success(gSaleDisputeService.getDisputeNumber());
    }


}
